/*********************************************************/
/*
	delegate
	TEMPLATE_ARGS = DELEGATE_TEMPLATE_ARGS
	FUNCTION_ARGS = DELEGATE_FUNCTION_ARGS
	FUNCTION_PARA = DELEGATE_FUNCTION_PARA
	CLASS_MEMBER  = DELEGATE_CLASS_MEMBER 
	CLASS_MEMBER_ASSIGN  = DELEGATE_CLASS_ASSIGN
	CLASS_MEMBER_PARA    = DELEGATE_CLASS_PARA
*/
template<typename BindType, typename ClassType, typename Ret DELEGATE_TEMPLATE_ARGS>
class delegate<Ret(DELEGATE_FUNCTION_ARGS), BindType, ClassType>
{
public:
	typedef functor<Ret(DELEGATE_FUNCTION_ARGS), BindType, ClassType> functor_type;
	typedef typename functor_type::return_type return_type;

	delegate(const functor_type& _functor DELEGATE_FUNCTION_PARA)
		:functor_(_functor) DELEGATE_CLASS_ASSIGN
	{

	}

	Ret operator()()
	{
		return functor_(DELEGATE_CLASS_PARA);
	}

	Ret Do()
	{
		return functor_(DELEGATE_CLASS_PARA);
	}

	functor_type& getFunctor() {return functor_;}

private:
	functor_type functor_;

	DELEGATE_CLASS_MEMBER;

	delegate(const delegate&);
	delegate& operator=(const delegate&);
};

/*
	delegate_list
	TEMPLATE_ARGS = DELEGATE_TEMPLATE_ARGS
	FUNCTION_ARGS = DELEGATE_FUNCTION_ARGS
	FUNCTION_PARA = DELEGATE_FUNCTION_PARA
	CLASS_MEMBER  = DELEGATE_CLASS_MEMBER 
	CLASS_MEMBER_ASSIGN  = DELEGATE_CLASS_ASSIGN
	CLASS_MEMBER_PARA    = DELEGATE_CLASS_PARA
*/
template<typename BindType, typename ClassType, typename Ret DELEGATE_TEMPLATE_ARGS>
class delegate_list<Ret(DELEGATE_FUNCTION_ARGS), BindType, ClassType>
{
public:
	typedef functor_list<Ret(DELEGATE_FUNCTION_ARGS), BindType, ClassType> functor_list_type;
	typedef functor<Ret(DELEGATE_FUNCTION_ARGS), BindType, ClassType> functor_type;
	typedef typename functor_type::return_type return_type;

	delegate_list(const functor_type& _functor DELEGATE_FUNCTION_PARA)
		:functor_(_functor) DELEGATE_CLASS_ASSIGN
	{
	}

	Ret operator()()
	{
		return functor_(DELEGATE_CLASS_PARA);
	}

	functor_list_type& getFunctor() {return functor_;}

private:
	functor_list_type functor_;

	DELEGATE_CLASS_MEMBER;

	delegate_list(const delegate_list&);
	delegate_list& operator=(const delegate_list&);
};

/*
	delegate_type
	TEMPLATE_ARGS = DELEGATE_TEMPLATE_ARGS
	FUNCTION_ARGS = DELEGATE_FUNCTION_ARGS
 */
template<typename BindType, typename RtVal, typename ClassType DELEGATE_TEMPLATE_ARGS>
struct delegate_type<RtVal (ClassType::*)(DELEGATE_FUNCTION_ARGS), BindType>
{
	typedef delegate<RtVal (DELEGATE_FUNCTION_ARGS), BindType, ClassType> type;
	typedef delegate_list<RtVal (DELEGATE_FUNCTION_ARGS), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal DELEGATE_TEMPLATE_ARGS>
struct delegate_type<RtVal (*)(DELEGATE_FUNCTION_ARGS), BindType>
{
	typedef delegate<RtVal (DELEGATE_FUNCTION_ARGS), BindType, ClassStub> type;
	typedef delegate_list<RtVal (DELEGATE_FUNCTION_ARGS), BindType, ClassStub> list_type;
};




/*********************************************************/

